package com.yxh.activity;

import java.util.LinkedHashMap;
import java.util.Timer;
import java.util.TimerTask;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.yxh.R;
import com.yxh.dto.UserDto;
import com.yxh.service.Task;

public class SettingFeedBackActivity extends BaseActivity implements
		OnClickListener {

	private EditText et1;
	private InputMethodManager inputMethodManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_setting_feedback);
		((TextView) findViewById(R.id.head_layout_tv)).setText("意见反馈");

		et1 = (EditText) findViewById(R.id.et1);
		findViewById(R.id.btn1).setOnClickListener(this);
		
		inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				inputMethodManager.toggleSoftInput(0,
						InputMethodManager.HIDE_NOT_ALWAYS);
			}
		}, 150);

		overridePendingTransition(R.anim.enter_righttoleft, R.anim.noanim);
	}

	@Override
	public void onClick(View view) {
		if (view.getId() == R.id.btn1) {
			commitFdContent();
		}
	}
	

	private void commitFdContent() {
		String data = String.valueOf(et1.getText());
		if (data.trim().equals("")) {
			showToast("请填写您的意见反馈");
			et1.setFocusable(true);
			return;
		}

		LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
		map.put("s", "other/feedback");
		map.put("data", data);
		getData(map, Task.SEND_FEED_BACK, 1);

	}
	

	@Override
	public void refresh(Object... param) {
		try {
			int operType = (Integer) param[0];
			Object obj = param[1];
			closeDialog();
			switch (operType) {
			case Task.SEND_FEED_BACK:

				if (obj != null) {
					UserDto dto = (UserDto) obj;
					if ("1".equals(dto.result)) {
						showToast("感谢您的建议，我们会尽快为您处理.");
						finish();
					} else
						showToast(dto.message);

				} else {
					showToast("网络连接异常,请检查网络");
				}

				break;

			default:
				break;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
